/****************************************************************************
**
** FontsManager.h
**
** Copyright (C) August 2014 Hotride
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
*****************************************************************************
*/
//---------------------------------------------------------------------------
#ifndef FontsManagerH
#define FontsManagerH
//--------------------------------------------------------------------------
const float g_UnicodeSpaceWidth = 8.0f;
const float g_ItalicFontKoeff = 3.3f;
//--------------------------------------------------------------------------
class TFontsManager
{
private:
	FONT_MAP m_Font;
	
	DWORD m_UnicodeFontAddress[20];
	DWORD m_UnicodeFontSize[20];

	bool m_SavePixels;

	bool m_UseHTML;
	
	bool GenerateABase(BYTE &font, TEXT_TEXTURE_HEADER &th, const char *str, WORD &color, float &width, TEXT_ALIGN_TYPE &align, WORD &flags);

	bool GenerateWBase(BYTE &font, TEXT_TEXTURE_HEADER &th, const wchar_t *str, WORD &color, BYTE &cell, float &width, TEXT_ALIGN_TYPE &align, WORD &flags);

public:
	TFontsManager();
	~TFontsManager();
	
	SETGET(bool, SavePixels)
	SETGET(bool, UseHTML)
	
	void LoadFonts(DWORD Address, DWORD Size);
	void SetUnicodeFontData(int Pos, DWORD Address, DWORD Size);
	
	//ASCII
	float GetFontOffsetY(BYTE Number, BYTE Index);
	int GetWidthA(BYTE font, const char *str, int len = 0);
	int GetHeightA(BYTE font, const char *str, float width = 0.0f, TEXT_ALIGN_TYPE align = TS_LEFT, WORD flags = 0);
	int GetHeightA(PMULTILINES_FONT_INFO info);
	string GetTextByWidthA(BYTE font, const char *str, int len, float width, bool IsCropped);
	PMULTILINES_FONT_INFO GetInfoA(BYTE font, const char *str, int len, TEXT_ALIGN_TYPE align, WORD flags, float width);
	bool GenerateA(BYTE font, TEXT_TEXTURE_HEADER &th, const char *str, WORD color = 0, float width = 0.0f, TEXT_ALIGN_TYPE align = TS_LEFT, WORD flags = 0);
	void DrawA(BYTE font, const char *str, WORD color, float X, float Y, float width = 0.0f, TEXT_ALIGN_TYPE align = TS_LEFT, WORD flags = 0);



	//Unicode
	int GetWidthW(BYTE font, const wchar_t *str, int len = 0);
	int GetHeightW(BYTE font, const wchar_t *str, float width = 0.0f, TEXT_ALIGN_TYPE align = TS_LEFT, WORD flags = 0);
	int GetHeightW(PMULTILINES_FONT_INFO info);
	wstring GetTextByWidthW(BYTE font, const wchar_t *str, int len, float width, bool IsCropped);
	PMULTILINES_FONT_INFO GetInfoW(BYTE font, const wchar_t *str, int len, TEXT_ALIGN_TYPE align, WORD flags, float width);
	bool GenerateW(BYTE font, TEXT_TEXTURE_HEADER &th, const wchar_t *str, WORD color = 0, BYTE cell = 30, float width = 0.0f, TEXT_ALIGN_TYPE align = TS_LEFT, WORD flags = 0);
	void DrawW(BYTE font, const wchar_t *str, WORD color, float X, float Y, BYTE cell = 30, float width = 0.0f, TEXT_ALIGN_TYPE align = TS_LEFT, WORD flags = 0);
};
//--------------------------------------------------------------------------
#endif